package com.hwc.demo.dubbo.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hwc.demo.dubbo.bean.UserAddress;
import com.hwc.demo.dubbo.service.OrderService;
import com.hwc.demo.dubbo.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class OrderServiceImpl implements OrderService{
	@Reference //远程bean
	UserService userService;
	
	@HystrixCommand(fallbackMethod = "fallbackMethod")
	@Override
	public List<UserAddress> initOrderAddress(Integer userId) {
		//调用户服务（假想userService的实现在另一台机器）
		List<UserAddress> address_list = userService.getUserAddressList(userId);
		
		return address_list;
	}
	//Hystrix容错回退方法
	public List<UserAddress> fallbackMethod(Integer userId){
		return Arrays.asList(new UserAddress("异常地址", 0));
	}
}
